package com.bileetacrm;

import java.util.List;
import java.util.Vector;

import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.view.ViewPager;
import android.view.Window;
import android.view.WindowManager;

import com.bileetacrm.BileetaPagerAdapter;;

public class BileetaFragmentActivity extends FragmentActivity{
	/** maintains the pager adapter*/
	private BileetaPagerAdapter mPagerAdapter;
	int DisplayOption = 0;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		this.requestWindowFeature(Window.FEATURE_NO_TITLE);
		this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
				WindowManager.LayoutParams.FLAG_FULLSCREEN);
		super.setContentView(R.layout.bileeta_fragment_activity);
		//initialsie the pager
		Bundle extras = getIntent().getExtras();
		if (extras != null) {
			DisplayOption = 1;
		} else {
			DisplayOption = 0;
		}
		this.initialisePaging();
	}
	
	/**
	 * Initialise the fragments to be paged
	 */
	private void initialisePaging() {

		List<Fragment> fragments = new Vector<Fragment>();
		if(DisplayOption == 0){
			fragments.add(Fragment.instantiate(this, BileetaSalesInquiryListActivity.class.getName()));
			fragments.add(Fragment.instantiate(this, BileetaNewLeadActiviy.class.getName()));
		}
		else{
			fragments.add(Fragment.instantiate(this, BileetaNewLeadActiviy.class.getName()));
			fragments.add(Fragment.instantiate(this, BileetaSalesInquiryListActivity.class.getName()));
		}
		this.mPagerAdapter  = new BileetaPagerAdapter(super.getSupportFragmentManager(), fragments);
		//
		ViewPager pager = (ViewPager)super.findViewById(R.id.viewpager);
		pager.setAdapter(this.mPagerAdapter);
	}
	
	@Override
	public void onBackPressed() {
		Intent myIntent = new Intent(BileetaFragmentActivity.this,
				BileetaDashbordActivity.class);
		startActivityForResult(myIntent, 0);
		// code here to show dialog
		super.onBackPressed(); // optional depending on your needs
	}
}
